from rest_framework.serializers import ModelSerializer,SerializerMethodField
from goods.models import *


class BrandSer(ModelSerializer):
    class Meta:
        fields = '__all__'
        model = Brand


class SKUSer(ModelSerializer):
    class Meta:
        fields = '__all__'
        model = SKU


class SPUSer(ModelSerializer):
    brand_spu_name = SerializerMethodField(read_only=True)

    def get_brand_spu_name(self, obj):
        return obj.brand.brand_name

    class Meta:
        fields = '__all__'
        model = SPU


class SpecSer(ModelSerializer):
    spu_name = SerializerMethodField(read_only=True)

    def get_spu_name(self, obj):
        return obj.spu.name

    class Meta:
        fields = '__all__'
        model = SPUSpecification


class OptionSer(ModelSerializer):
    spec_name = SerializerMethodField(read_only=True)

    def get_spec_name(self, obj):
        return obj.spec.name

    class Meta:
        fields = '__all__'
        model = SpecificationOption


class PicSer(ModelSerializer):

    class Meta:
        fields = '__all__'
        model = SKUImage



